﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using Abp.Application.Editions;
using Abp.Application.Services.Dto;
using Abp.Auditing;
using Abp.AutoMapper;
using Abp.Domain.Entities;
using KelonProud.Administration.Domain.Authorization;
using KelonProud.Domain.Dtos;
using KelonProud.Extensions;

namespace KelonProud.Administration.Dtos
{
    [AutoMap(typeof(Navigation))]
    public class NavigationInputDto:KelonProudEntityDto
    {
        [DisplayName("名称")]
        [Required(ErrorMessage = "菜单/功能名称必须填写")]
        public virtual string Name { get; set; }

        [DisplayName("编码")]
        [Required(ErrorMessage = "菜单/功能编码必须填写")]
        [MaxLength(15,ErrorMessage = "菜单/功能编码长度不能超过15个字符")]
        [MinLength(4, ErrorMessage = "菜单/功能编码长度不能小于4个字符")]
        public virtual string Code { get; set; }

        [DisplayName("URL地址")]
        public virtual string ActionUrl { get; set; }

        [DisplayName("图标")]
        [StringLength(50)]
        [Required(ErrorMessage = "菜单/功能图标必须选择")]
        public virtual string Icon { get; set; }

        [DisplayName("是否隐藏")]
        public virtual bool IsHide { get; set; }

        [DisplayName("级别")]
        [Column("Level")]
        public virtual byte Level { get; set; }

        [DisplayName("顺序")]
        [Column("Order")]
        public virtual byte Order { get; set; }

        [StringLength(100)]
        public virtual string IdPath { get; set; }

        [DisplayName("名称路径")]
        [StringLength(100)]
        public virtual string NamePath { get; set; }

        [DisplayName("类型")]
        public virtual NavigationType Type { get; set; }

        [DisplayName("类型")]
        public virtual string TypeName => Type.GetDisplayName();

        [DisplayName("描述")]
        [StringLength(300)]
        public virtual string Description { get; set; }

        [DisplayName("租户ID")]
        public int? TenantId { get; set; }

        [DisplayName("上级ID")]
        public virtual int? ParentId { get; set; }

        [DisplayName("上级菜单")]
        public virtual string ParentName { get; set; }

        public virtual string[] RoleIds { get; set; }

        public virtual string[] EditionIds { get; set; }

        public IEnumerable<RoleOutPutDto> RoleDtos { get; set; }

        public IEnumerable<EditionOutput> Editions { get; set; }

        public IEnumerable<TenantOutputDto> Tenants { get; set; }

        public bool NavIsInRole(RoleOutPutDto roleOutPut)
        {
            return RoleIds?.Contains(roleOutPut.Id.ToString()) ?? false;
        }

        public bool NavIsInEdit(EditionOutput editionOutput)
        {
            return RoleIds?.Contains(editionOutput.Id.ToString()) ?? false;
        }

        public bool FunctionAdd { get; set; }
        public bool FunctionEdit { get; set; }
        public bool FunctionDelete { get; set; }
    }

    [AutoMap(typeof(Navigation))]
    public class NavigationOutputDto : NavigationInputDto
    {
        [DisplayName("创建时间")]
        public DateTime CreationTime { get; set; }

        [Column("创建用户ID")]
        public long? CreatorUserId { get; set; }

        [DisplayName("创建用户")]
        public string CreatorUserName { get; set; }

        [DisplayName("最后修改时间")]
        public DateTime? LastModificationTime { get; set; }

        [DisplayName("最后修改用户")]
        public long? LastModifierUserId { get; set; }

    }
}
